package com.jswdwsx.esign.protocol

import com.jswdwsx.esign.entity.UserPO
import com.jswdwsx.esign.protocol.request.*
import com.jswdwsx.esign.protocol.response.*
import retrofit2.http.*

interface EsignApi {

    /**
     * 查询个人账号
     */
    @GET("/v1/accounts/{accountId}")
    fun queryAccount(
        @Path("accountId") accountId: String
    ): EsignResp<UpdateUserResp>

    /**
     * 创建个人账号
     */
    @POST("v1/accounts/createByThirdPartyUserId")
    fun createAccount(
        @Body user: UserReq
    ): EsignResp<CreateUserResp>

    /**
     * 修改个人账号
     */
    @PUT("/v1/accounts/{accountId}")
    fun updateAccount(
        @Path("accountId") accountId: String,
        @Body user: UserPO
    ): EsignResp<UpdateUserResp>

    /**
     * 创建个人模板印章
     */
    @POST("/v1/accounts/{accountId}/seals/personaltemplate")
    fun createPersonalSeal(
        @Path("accountId") accountId: String,
        @Body personalSealReq: PersonalSealReq
    ): EsignResp<SealResp>

    /**
     * 创建机构账号
     */
    @POST("v1/organizations/createByThirdPartyUserId")
    fun createOrganization(
        @Body orgReq: OrgReq
    ): EsignResp<OrgResp>

    /**
     * 查询机构账号
     */
    @GET("v1/organizations/{orgId}")
    fun queryOrganization(
        @Path("orgId") orgId: String
    ): EsignResp<QueryOrgResp>

    /**
     * 修改机构账号
     */
    @PUT("v1/organizations/{orgId}")
    fun updateOrganization(
        @Path("orgId") orgId: String,
        @Body updateOrgReq: UpdateOrgReq
    ): EsignResp<UpdateOrgResp>

    /**
     * 创建机构模板印章
     */
    @POST("/v1/organizations/{orgId}/seals/officialtemplate")
    fun createOrgSeal(
        @Path("orgId") orgId: String,
        @Body orgSeal: OrgSealReq
    ): EsignResp<SealResp>

    /**
     * 创建个人/机构图片印章
     */
    @POST("/v1/accounts/{accountId}/seals/image")
    fun createSealImage(
        @Path("accountId") accountId: String,
        @Body sealImageReq: SealImageReq
    ): EsignResp<SealImageResp>

    /**
     *
     * 查询机构印章
     */
    @GET("/v1/organizations/{orgId}/seals")
    fun getOrgSeals(
        @Path("orgId") orgId: String
    ): EsignResp<QueryOrgSealResp>

    /**
     * 通过上传文件创建模板,同时获取上传url
     */
    @POST("/v1/docTemplates/createByUploadUrl")
    fun createTemplate(
        @Body createTemplateReq: CreateFileTemplateReq
    ): EsignResp<CreateTemplateResp>

    /**
     * 为模板添加输入项组件
     */
    @POST("/v1/docTemplates/{templateId}/components")
    fun addComponents2Template(
        @Path("templateId") templateId: String,
        @Body addComponentsReq: AddComponentsReq
    ): EsignResp<String>

    /**
     * 查询模板
     */
    @GET("/v1/docTemplates/{templateId}")
    fun queryTemplate(
        @Path("templateId") templateId: String
    ): EsignResp<QueryFileTemplateResp>

    /**
     * 根据模板创建文件
     */
    @POST("/v1/files/createByTemplate")
    fun createFileByTemplate(
        @Body fileReq: CreateFileByTemplateReq
    ): EsignResp<CreateFileByTemplateResp>

    /**
     * 创建签署流程
     */
    @POST("/v1/signflows")
    fun createFlow(
        @Body flow: FlowReq
    ): EsignResp<FlowResp>

    /**
     * 添加流程文档
     */
    @POST(" /v1/signflows/{esignFlowId}/documents")
    fun addDoc2Flow(
        @Path("esignFlowId") flowId: String,
        @Body addDocs2FlowReq: AddDocs2FlowReq
    ): EsignResp<EmptyResp>

    /**
     * 获取签署完成的流程文档
     */
    @GET(" /v1/signflows/{esignFlowId}/documents")
    fun docsDownloadUrl(
        @Path("esignFlowId") flowId: String
    ): EsignResp<DocsDownloadUrlResp>

    /**
     * 添加对接平台自动盖章签署区
     */
    @POST(" /v1/signflows/{esignFlowId}/signfields/platformSign")
    fun addPlatformSign2Flow(
        @Path("esignFlowId") flowId: String,
        @Body addPlatformSignFields2FlowReq: AddPlatformSignFields2FlowReq
    ): EsignResp<EmptyResp>

    /**
     * 添加用户自动盖章签署区
     */
    @POST(" /v1/signflows/{esignFlowId}/signfields/autoSign")
    fun addAutoSign2Flow(
        @Path("esignFlowId") flowId: String,
        @Body addAutoSignFields2FlowReq: AddAutoSignFields2FlowReq
    ): EsignResp<EmptyResp>

    /**
     * 添加用户手动盖章签署区
     */
    @POST(" /v1/signflows/{esignFlowId}/signfields/handSign")
    fun addHandSign2Flow(
        @Path("esignFlowId") flowId: String,
        @Body addHandSignFields2FlowReq: AddHandSignFields2FlowReq
    ): EsignResp<EmptyResp>

    /**
     * 开启签署流程
     */
    @PUT("/v1/signflows/{esignFlowId}/start")
    fun startFlow(
        @Path("esignFlowId") flowId: String
    ): EsignResp<FlowResp>

    /**
     * 获取签署地址
     */
    @GET("/v1/signflows/{esignFlowId}/executeUrl")
    fun getSignUrl(
        @Path("esignFlowId") flowId: String,
        @Query("accountId") accountId: String,
        @Query("organizeId") organizeId: String? = null,
        @Query("urlType") urlType: Int = 0
    ): EsignResp<SignUrlResp>

    /**
     * 签署流程查询
     */
    @GET("v1/signflows/{esignFlowId}")
    fun getFlow(
        @Path("esignFlowId") flowId: String
    ): EsignResp<QueryFlowResp>

    /**
     * 签署流程签署区查询
     */
    @GET("v1/signflows/{esignFlowId}/signfields")
    fun getFlowSignFields(
        @Path("esignFlowId") flowId: String
    ): EsignResp<QueryFlowSignFieldsResp>

    /**
     * 设置静默授权
     */
    @POST("/v1/signAuth/{accountId}")
    fun setSilentSign(
        @Path("accountId") accountId: String
    ): EsignResp<Boolean>

    /**
     * 一步发起签署
     */
    @POST("/api/v2/signflows/createFlowOneStep")
    fun createFlowOneStep(
        @Body oneStepReq: CreateFlowOneStepReq
    ): EsignResp<FlowResp>
}